package com.yq.core.json;

import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;


/**
 * 
 * 文件名: BnEmployeeController.java
 * 创建人: yinquan
 * 创建日期: 2017-03-21 15:42:34
 * 描  述: 人员信息表
 * 版本号： 1.0
 */

public class BaseData {

    private static Logger logger = LoggerFactory.getLogger(BaseData.class);

	// 页面跳转
    public static Map<String, Object> getConfig(ServletRequest request, String controllerNameLong) {
		String entityName = controllerNameLong.replace("com.yq.master.controller.", "").replace("Controller", "");

    	// 获取配置文件
		String json = "{" +
			"SysMenuTop:" + SysMenuTopData.config() + "," +
			"SysMenuLeft:" + SysMenuTopData.config() + "," +
		"}";

    	Map<String, Object> configure = (Map<String, Object>) JSON.parse(json);
    	
    	// 获取配置信息
    	String uri = ((HttpServletRequest) request).getRequestURI();
		if(configure.get(entityName)==null) {
			return null;
		}
		return (Map<String, Object>)((Map<String, Object>) configure.get(entityName)).get(getKey(request, uri));
    }

	// 获取实体对象
	public static Map<String, Object> getConfig(String entityNameLong) {
		String entityName = entityNameLong.replace("class com.yq.core.entity.", "");
		// 获取配置文件
		String json = "{" +
			"CodCode:" + CodCodeData.config() + "," +
			"SysUser:" + SysUserData.config() + "," +
			"SysPower:" + SysPowerData.config() + "," +
		"}";
		Map<String, Object> configure = (Map<String, Object>) JSON.parse(json);
		return (Map<String, Object>) configure.get(entityName.replace("Entity", ""));
	}
    
    private static String getKey(ServletRequest request, String uri) {
		String url[] = uri.split("/");
		String m = request.getParameter("_m");
		return url[url.length-1] + m.substring(0, 1).toUpperCase() + m.substring(1);
    }
}
